<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增样本管理')" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-data-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">机构：</label>
                <div class="col-sm-8">
                    <select  class="form-control" name="orgId" required>
                        <option value="">--请选择机构--</option>
                        <option th:each="item:${@dict.getType('fx_org')}" th:value="${item.getDictValue()}" >[[${item.getDictLabel()}]]</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="font-noraml">上传文件</label>
                <input id="fileUploadPic" type="file"  name="file" >
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上传路径：</label>
                <div class="col-sm-8">
                    <input name="url" id="picUrl" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
            <div id="loading" style="display: none;">
                <div  style=" background-color: rgba(255,255,255,0); position:absolute; left:0; top:0; width:100%;height:100%; z-index: 1;"></div>
                <div style="width: 350px;max-height: 250px; overflow-y: auto; line-height: 20px; position:absolute;left: 50%; top: 30%; margin-left: -130px;font-size: 14px;
border:1px #ddd solid;z-index: 2; background-color: #fff; padding: 5px; display: flex;  ">
                    <span style="padding-right: 8px;width: 40px; float: left; display: table-cell;"><img src="../static/img/loading.gif" width="40" height="40"/></span>
                    <span id="step_show">文件上传中…</span>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <th:block th:include="include :: importFileUpLoad" />
    <script th:inline="javascript">
        var prefix = ctx + "system/data"
        var code = 'data' + Math.floor(Math.random()*(100001)+10000)
        $("#form-data-add").validate({
            focusCleanup: true
        });




        function submitHandler() {
            if ($.validate.form()) {
                $('#loading').css('display','block');
                $('#step_show').html('zip开始解压缩…');
                var data = $('#form-data-add').serializeArray();
                console.log(data)
                data.push({ "name": "code", "value": code});
                console.log(data)
                $.operate.save(prefix + "/add", data);
                var interval = setInterval(function(){
                    $.ajax({
                        type: "GET",
                        url: "../progress/getProgress?code="+code,
                        contentType: "application/json",
                        success: function (r) {
                            let queueModel = r.queueModel;
                            let curStatus = queueModel.curStatus;

                            if(curStatus == 'analysis_unzip_start') {
                                $('#step_show').html('模型zip文件解压缩中…');
                            }
                            if(curStatus == 'analysis_conda_unzip_start') {
                                $('#step_show').html('运行环境zip文件解压缩中…');
                            }
                            if(curStatus == 'analysis_start_sh_start') {
                                $('#step_show').html('开始生成启动脚本…');
                            }
                            if(curStatus == 'analysis_shutdown_sh_start') {
                                $('#step_show').html('开始生成停止脚本…');
                            }

                            if(curStatus == 'all_end') {
                                $('#loading').css('display','none');
                                clearInterval(interval);
                            }
                        }
                    });


                }, 200);

            }
        }
    </script>
</body>
</html>